package com.example.demo.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.example.demo.service.ItemService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ItemController {

	//注入服务提供方暴露的接口，通过@Reference注解，dubbo会在扫描的时候自动代理接口，然后通过rpc调用远程服务。
	//如果用xml配置方式，需要将@Reference换成@Autowired。
	// @Autowired
	@Reference
	ItemService itemService;

	@RequestMapping("/test")
	public String canBuy(@RequestParam("id") String id) {
		System.out.println(id);
		boolean flag = itemService.checkItemStatus(id);
		if (flag) {
			return "can buy!";
		} else {
			return "can not buy!";
		}
	}

	@GetMapping("/sayHello")
	public String sayHello(@RequestParam("name") String name) {
		return itemService.sayName(name);
	}
}
